package main

import (
	"fmt"
)

//       1 9 2 8  7 6  4  5
//9        1  2 8  7 6  4  5
//9   8       1  2   7 6  4  5
//9   8    7       1  2    6  4  5
//  选择排序
func findMax(arr []int) int {
	length := len(arr) //数组长度
	if length <= 1 {
		return arr[0]
	} else {
		max := arr[0]

		for i := 0; i < length; i++ {
			if arr[i] > max {
				max = arr[i]
			}
		}
		return max
	}
}

func selectSort(arr []int) []int {
	length := len(arr) //数组长度
	if length <= 1 {
		return arr
	} else {
		max := 0

		for i := 0; i < length-1; i++ {
			max = i

			for j := i + 1; j < length; j++ {
				if arr[j] > arr[max] {
					max = j
				}
			}

			if max != i {
				arr[i], arr[max] = arr[max], arr[i]
			}

		}

	}
	return arr
}

func main() {
	arr := []int{5, 10, 7, 8, 9}
	fmt.Println(findMax(arr))

	fmt.Println(selectSort(arr))

}
